package com.sskj.market.ui.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.adapter.BaseAdapter;
import com.sskj.lib.adapter.ViewHolder;
import com.sskj.lib.base.BaseActivity;
import com.sskj.market.R;
import com.sskj.market.R2;
import com.sskj.market.bean.ShoppingBean;
import com.sskj.market.presenter.OverSeasPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 海外分类Activity
 * @author Hey
 * Create at  2019/07/25
 */
@Route(path = RConfig.MARKET_ACTIVITY_OVERSEAS)
public class OverSeasActivity extends BaseActivity<OverSeasPresenter> {
    @BindView(R2.id.tvTitle)
    TextView tvTitle;
    @BindView(R2.id.tvReturn)
    TextView tvReturn;
    @BindView(R2.id.ivBack)
    LinearLayout ivBack;
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.smartRefreshLayout)
    SmartRefreshLayout smartRefreshLayout;
    @BindView(R2.id.ivRight)
    ImageView ivRight;
    private BaseAdapter<ShoppingBean> adapter;
    private ShoppingBean shoppingBean;
    private List<ShoppingBean> data = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.market_activity_over_seas;
    }

    @Override
    public OverSeasPresenter getPresenter() {
        return new OverSeasPresenter();
    }

    @Override
    public void initView() {
        tvTitle.setText(App.INSTANCE.getString(R.string.market_overSeasActivity1));
        tvReturn.setVisibility(View.VISIBLE);
        ivRight.setColorFilter(R.color.lib_618);
    }

    @Override
    public void initData() {
        shoppingBean = new ShoppingBean();
        //recyclerview初始化
        recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setLeftPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setRightPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 1))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.super_divi_split))
        );

        //假数据
        for (int i = 0; i < 10; i++) {
            shoppingBean.setTitle(App.INSTANCE.getString(R.string.market_overSeasActivity2) + i);
            shoppingBean.setMoney("89.00 LAC" + i);
            shoppingBean.setNumber(App.INSTANCE.getString(R.string.market_overSeasActivity3) + i);
            data.add(shoppingBean);
        }

        //填充适配器
        if (data == null) {
            return;
        }
        adapter = new BaseAdapter<ShoppingBean>(R.layout.activity_shopping_item, null, recyclerView) {
            @Override
            public void bind(ViewHolder holder, ShoppingBean item) {
                holder.setText(R.id.tvTitleShopItem, item.getTitle());
                holder.setText(R.id.tvMoneyShopItem, item.getMoney());
                holder.setText(R.id.tvNumberShopItem, item.getNumber());
            }
        };

        adapter.addData(data);
    }

}
